var t = a(require("@vant/weapp/toast/toast")), e = a(require("@vant/weapp/dialog/dialog"));

function a(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var i = require("../../utils/config"), n = getApp(), o = require("../../utils/request"), s = require("../../utils/byte"), r = require("../../utils/storage"), c = require("../../utils/api"), d = require("../../utils/date");

Page({
    data: {
        nodateImg: i.resourceRoot + "nodata2.png",
        active: 0,
        loadingHidden: !0,
        themeColor: n.globalData.themeColor,
        loadinginfo: "报告加载中...",
        show: !1,
        Title: "",
        studyid: "",
        Conclusion: "",
        HealthCare: "",
        keyWordsList: [],
        keyWordsListExcept: [],
        NormalItemList: [],
        ExceptResultList: [],
        type: "",
        parameter1: "",
        parameter2: "",
        nvalue: "",
        vantabsitemShow: !0,
        checkboxname: "只显示异常数据",
        checkboxvalue: !1,
        filePath: "",
        showPopup: !1,
        name: "",
        stid: "",
        reportid: "",
        showedsatisfactionquestion: !1,
        imagePath: i.resourceRoot,
        phoneHeight: getApp().globalData.systemHeight,
        phoneWidth: getApp().globalData.systemWidth,
        x: getApp().globalData.systemWidth - 80,
        y: getApp().globalData.systemHeight - 200,
        moveWidth: getApp().globalData.systemWidth,
        moveHeight: getApp().globalData.systemHeight - 40,
        interpretationOnlineSrc: "",
        openFilmPrint: !1,
        canFilmPrint: !1,
        showDialog: !1,
        reportYear: "",
        showExtraTips: !1
    },
    onLoad: function(t) {
        this.setData({
            studyid: t.studyid,
            type: t.type,
            parameter1: t.parameter1,
            parameter2: t.parameter2,
            nvalue: t.nvalue,
            name: t.name,
            stid: t.stid,
            reportid: t.reportid,
            showSatisfactionQuestion: t.showSatisfactionQuestion,
            reportYear: 16 === t.stid.length ? "20" + t.stid.substring(6, 8) : "20" + t.stid.substring(2, 4)
        }), this.getInterpretationOnlineSrc(), this.loadReport(), this.getIsInsOnline(t.stid), 
        this.checkCheckTimeCanFilmPrint(t.stid), this.getFilmPrintHoliday();
    },
    getFilmPrintHoliday: function() {
        var t = this;
        o.request(o.HttpMethod.GET, c.apiRoute.getFilmPrintHoliday, {}).then(function(e) {
            if ("20000" == e.code) {
                var a = e.data.wcaValue.split(","), i = new Date(a[0]), n = new Date(a[1]), o = new Date();
                o >= i && o < n && t.setData({
                    showExtraTips: !0
                });
            }
        });
    },
    getIsInsOnline: function(t) {
        var e = this, a = "";
        12 == t.length ? a = t.substring(0, 2) : 16 == t.length && (a = t.substring(0, 3)), 
        "" != a && o.request(o.HttpMethod.GET, c.apiRoute.isInsOnline + Number(a), {}).then(function(t) {
            "20000" == t.code && e.setData({
                openFilmPrint: t.data
            });
        });
    },
    getInterpretationOnlineSrc: function() {
        var t = this;
        o.request(o.HttpMethod.GET, c.apiRoute.getInterpretationOnlineSrc, {}).then(function(e) {
            "20000" == e.code && t.setData({
                interpretationOnlineSrc: i.resourceRoot + e.data.wcaValue
            });
        });
    },
    onSubmit: function() {
        var t = this;
        this.setData({
            loadingHidden: !1,
            loadinginfo: "报告下载中..."
        }), o.request();
        var e = "".concat(i.reportUrl, "/PDFWechat?studyId=").concat(this.data.studyid, "&isA=true&source=WeChatApplet");
        o.request(o.HttpMethod.GET, e, {}).then(function(e) {
            if (null != e.Data) {
                var a = wx.env.USER_DATA_PATH + "/" + t.data.name + "(" + t.data.stid + ").pdf";
                wx.downloadFile({
                    url: e.Data.Url,
                    filePath: a,
                    success: function(e) {
                        t.setData({
                            loadingHidden: !0,
                            loadinginfo: "报告加载中..."
                        }), 200 === e.statusCode && (t.setData({
                            filePath: a,
                            showPopup: !1
                        }), wx.getFileSystemManager().getFileInfo({
                            filePath: a,
                            success: function(e) {
                                var i = s.changeByte(e.size);
                                wx.navigateTo({
                                    url: "/pages/reportInfo-share/reportInfo-share?filePath=".concat(a, "&stid=").concat(t.data.stid, "&name=").concat(t.data.name, "&size=").concat(i, "&reportid=").concat(t.data.reportid, "&showedsatisfactionquestion=").concat(t.data.showedsatisfactionquestion)
                                });
                            }
                        }));
                    }
                });
            }
        });
    },
    viewReport: function() {
        "" == this.data.filePath && (0, t.default)({
            message: "请先下载报告",
            duration: 5e3
        }), wx.openDocument({
            filePath: this.data.filePath,
            showMenu: !0,
            success: function(t) {
                console.log(t);
            }
        });
    },
    shareReport: function() {
        "" == this.data.filePath && (0, t.default)({
            message: "请先下载报告",
            duration: 5e3
        }), wx.shareFileMessage({
            filePath: this.data.filePath,
            success: function() {},
            fail: console.error
        });
    },
    closePopup: function() {
        this.setData({
            filePath: "",
            showPopup: !1
        });
    },
    loadReport: function() {
        var t = "".concat(i.reportUrl, "/reportquery?studyid=").concat(this.data.studyid, "&nvalue=").concat(this.data.nvalue, "&source=WeChatApplet");
        console.log(t, "报告地址");
        var e = this;
        e.setData({
            loadingHidden: !1,
            loadinginfo: "报告加载中..."
        }), o.request(o.HttpMethod.GET, t, {}).then(function(t) {
            t.Data && t.Data.NormalItemList && t.Data.NormalItemList.length ? e.setData({
                vantabsitemShow: !0,
                loadingHidden: !0,
                Conclusion: t.Data.Conclusion || "",
                HealthCare: t.Data.HealthCare || "",
                keyWordsList: t.Data.keyWordsList,
                NormalItemList: t.Data.NormalItemList,
                ExceptResultList: t.Data.ExceptResultList,
                keyWordsListExcept: t.Data.keyWordsListExcept,
                Title: t.Data.Title || ""
            }) : e.setData({
                vantabsitemShow: !1,
                loadingHidden: !0
            });
        });
    },
    showToast: function(t) {
        wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3
        });
    },
    onclickTab: function(t) {
        var e = t.detail.index;
        this.setData({
            active: e
        });
    },
    showPopup: function() {
        this.setData({
            show: !0
        });
    },
    onClose: function() {
        this.setData({
            show: !1
        });
    },
    checkboxChange: function() {
        this.setData({
            checkboxvalue: !this.data.checkboxvalue
        });
    },
    getReportOnline: function(t) {
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var e = r.getStorageSync(r.storageKey.uid), a = "id=" + e + "&name=" + this.data.name + "&studyId=" + this.data.stid, n = encodeURIComponent(a), o = i.reportInterpretationDetailUrl + n;
        e && this.data.name && this.data.stid ? wx.navigateTo({
            url: "/pages/webview/webview?h5=".concat(encodeURIComponent(o)),
            success: function() {
                wx.hideLoading();
            }
        }) : (wx.showToast({
            title: "体检信息不完整，暂不能进行报告解读",
            duration: 3e3,
            mask: !1,
            icon: "none"
        }), wx.hideLoading());
    },
    onShareAppMessage: function() {
        var t = this.data.studyid, e = this.data.type, a = this.data.parameter1, i = this.data.parameter2, n = this.data.nvalue, o = this.data.name, s = this.data.stid;
        return {
            title: "瑞慈体检预约 - 报告详情",
            path: "/pages/reportInfo/reportInfo?studyid=".concat(t, "&type=").concat(e, "&parameter1=").concat(a, "&parameter2=").concat(i, "&nvalue=").concat(n, "&").concat(o, "&stid=").concat(s)
        };
    },
    onShareTimeline: function() {
        var t = this.data.studyid, e = this.data.type, a = this.data.parameter1, i = this.data.parameter2, n = this.data.nvalue, o = this.data.name, s = this.data.stid;
        return {
            title: "瑞慈体检预约 - 报告详情",
            path: "/pages/reportInfo/reportInfo?studyid=".concat(t, "&type=").concat(e, "&parameter1=").concat(a, "&parameter2=").concat(i, "&nvalue=").concat(n, "&").concat(o, "&stid=").concat(s)
        };
    },
    filmPrintClick: function() {
        var t = new Date().getHours();
        t >= 8 && t < 15 ? this.setData({
            showDialog: !0
        }) : e.default.alert({
            title: "温馨提示",
            message: "尊敬的客户您好，放射胶片申请开放时间段为每日08:00--15:00，如有需要请在规定时间内进行申请。",
            messageAlign: "left"
        }).then(function() {});
    },
    onDialogConfirm: function() {
        this.setData({
            showDialog: !1
        }), wx.navigateTo({
            url: "/pages/film-print/film-print?checkNo=".concat(this.data.stid)
        });
    },
    onDialogCancel: function() {
        this.setData({
            showDialog: !1
        });
    },
    checkCheckTimeCanFilmPrint: function(e) {
        var a = this;
        o.request(o.HttpMethod.GET, c.apiRoute.getFilmPrintCheckInfoByCheckNo + e, {}).then(function(t) {
            if ("20000" == t.code && null != t.data.checkUserCheckTime && null != t.data.checkUserCheckTime && "" != t.data.checkUserCheckTime) {
                var e = d.formatDate(new Date(t.data.checkUserCheckTime), "yyyy-MM-dd HH:mm:ss"), i = d.formatDate(new Date("2020-01-01 00:00:00"), "yyyy-MM-dd HH:mm:ss");
                a.setData({
                    canFilmPrint: e >= i
                });
            }
        }).catch(function() {
            wx.hideLoading(), (0, t.default)({
                message: "获取体检信息异常",
                duration: 5e3
            });
        });
    }
});